
const db = require('../tool/db.js')
const bcrypt = require('bcrypt');



//验证手机号是否存在
async function mobileExist(data){
    let [res] = await db.query('select * from user where mobile = ' + data)
    return res
}

//验证用户名是否存在
async function userNameExist(data){
    let [res] = await db.query('select * from user where username = ?',[data])
    return res
}

//验证密码是否正确
async function repassword(pwd,info){
    let repwd =  await bcrypt.compare(pwd, info.password)
    return repwd
}

//验证支付密码是否正确
async function paypassword(pwd,info){
    let repwd =  await bcrypt.compare(pwd, info.paypassword)
    return repwd
}

//获取用户信息
async function userinfo(data){
    let [[userinfo]] = await db.query('select username,mobile,userImg,paypassword from user where id = ' + data)
    userinfo.paypassword = userinfo.paypassword ? true : false
    return userinfo
}
//获取用户支付密码
async function userpay(data){
    let [[userinfo]] = await db.query('select paypassword from user where id = ' + data)
    return userinfo 
}

//开发时获取用户信息
async function devuserinfo(data){
    let [[userinfo]] = await db.query('select * from user where id = ' + data)
    return userinfo

}

//根据订单编号获取订单信息
async function orderinfo(data){
    // let res = await db.query('select * from')
}

module.exports = {mobileExist,userNameExist,repassword,paypassword,userinfo,userpay,devuserinfo,orderinfo}
